<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/myJS/custom.js"></script>
    <script src="/static/moment/moment.min.js"></script>
    <script src="/static/JQuery/jquery-3.3.1.min.js"></script>
</head>
<body class="layui-layout-body" style="padding: 10px">

<form class="layui-form" action="" lay-filter="goodsEdit">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="orderdesc" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">收货地址</label>
            <div class="layui-input-inline">
                <select name="fkaddressid" id="fkaddressid" lay-search="" >
                    <option value=""></option>
                </select>
            </div>
        </div>
    </div>



    <div class="layui-col-md-offset5">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" lay-submit lay-filter="goodsSubmit">确认购买</button>
        </div>
    </div>
</form>

</body>

</html>

<script>

    layui.use(['form', 'layedit', 'laydate', 'layer', 'upload'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate;

        //加载类别信息下拉列表
        $.ajax({
            url:"/restful/find",
            type:"POST",
            data:JSON.stringify({
                firstTable:"addresses",
                wheres:[
                    {field:"addresses.fkuserid", value:getLoginUserid()}
                ]
            }),
            contentType: "application/json;charset=utf-8",
            dataType : "json",
            async:false,
            success : function(result) {
                var data = result.data;
                var count = result.count;
                for(var i = 0 ; i < count ; i ++){
                    $('#fkaddressid').append("<option value='" + data[i].addressid + "'>" +
                        data[i].addressname + "/" +
                        data[i].addressdesc + "/" +
                        data[i].contactphone +"</option>");
                }
                form.render("select");
            },
            error:function(result){
                layer.alert(result.msg);
                $('#fkaddressid').append("<option value=''>加载错误</option>");
            }
        });

        form.on('submit(goodsSubmit)', function(data){
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            data.field['selectData'] = JSON.parse(localStorage.orderSelectData);
            data.field['fkbuyerid'] = getLoginUserid();
            // alert(JSON.stringify(data.field));
            $.ajax({
                url:"/order/batchAdd",
                type:"POST",
                data:JSON.stringify(data.field),
                contentType: "application/json;charset=utf-8",
                dataType : "json",
                async:false,
                success : function(result) {
                    if(result.code == 0){
                        parent.layer.msg(result.msg, {icon:1});
                    }else{
                        parent.layer.msg(result.msg, {icon:5});
                    }
                },
                error:function(result){
                    parent.layer.msg(result.msg, {icon:5});
                }
            });
            parent.layer.close(index);
            return false;
        });


    });


</script>
